import authCheckApp from './authCheckApp'

/**
 * 获取用户信息
 * @since 1.0.0
 * @returns {Promise} 返回获取到的用户信息
 * @example
 * 
 * getUserInfo().then(res => {}).catch(err => {})
 */
function getUserInfo() {
    return new Promise((resolve, reject) => {
        authCheckApp()
            .then((result) => {
                // 发起请求
                window.WebViewJavascriptBridge.callHandler('getUserInfor', null, (response) => {
                    if (typeof response === 'string') {
                        response = JSON.parse(response)
                    }
                    // 返回状态值为0成功
                    if (response.status === 0) {
                        resolve(response)
                    } else {
                        // 设置返回数据状态值
                        reject(response)
                    }
                })
            }).catch((err) => {
                reject(err)
            })
    })
}

export default getUserInfo